package com.huonan.component.thread.functions.consumers;

import org.junit.Test;

import java.util.Arrays;
import java.util.List;
import java.util.function.Consumer;

/**
 * consumer： 函数式接口
 * 输入参数，不返回结果
 */
public class ConsumerTest {
    @Test
    public void test1() {
        List<String> list = Arrays.asList("applie", "banana", "cherry");
        Consumer<String> handler = s -> System.out.println(s.toUpperCase());
        CustomConsumer<String> handler2 = s -> System.out.println(s.toUpperCase());
//        list.forEach(handler);
        for (String l : list) {
            handler2.accept(l);
        }
    }

    @Test
    public void test2() {
        //调用，Java 8 函数式接口方式调用
        test3("libai", this::toUpperCase);

    }

    public void test3(String oldStr, Consumer<String> str) {
        //执行
        str.accept(oldStr);
    }

    public void toUpperCase(String str) {
        System.out.println("oldStr:" + str);
        System.out.println("newStr:" + str.toUpperCase());
    }

}
